package com.rtx.wms.std.asn.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.rtx.api.annotation.DataSourceAnnotation;
import com.rtx.wms.std.asn.bean.ApiReceiptdetailfinish;
import com.rtx.wms.std.asn.bean.ApiReceiptfinish;
import com.rtx.wms.std.asn.mapper.ApiReceiptdetailfinishMapper;
import com.rtx.wms.std.asn.mapper.ApiReceiptfinishMapper;
import com.rtx.wms.std.asn.service.ApiReceiptfinishService;
import com.rtx.wms.std.common.bean.Codelkup;
import com.rtx.wms.std.common.bean.WmsConstant;
import com.rtx.wms.std.validation.asn.ReceiptValidation;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zcw
 * @since 2023-04-18
 */
@Service
public class ApiReceiptfinishServiceImpl extends ServiceImpl<ApiReceiptfinishMapper, ApiReceiptfinish> implements ApiReceiptfinishService {

    @Autowired
    private ApiReceiptdetailfinishMapper apiReceiptdetailfinishMapper;
    
	@Autowired
	ReceiptValidation receiptValidation;

	@DataSourceAnnotation
    @Override
    public List<ApiReceiptfinish> selectApiReceiptfinishByWrapper(String whseid, LambdaQueryWrapper<ApiReceiptfinish> queryWrapper) {
        List<ApiReceiptfinish> ordersList = baseMapper.selectList(queryWrapper);
        for(ApiReceiptfinish o : ordersList){
            LambdaQueryWrapper<ApiReceiptdetailfinish> query = Wrappers.lambdaQuery();
            query.eq(ApiReceiptdetailfinish::getBatchid,o.getBatchid());
            o.setDetails(apiReceiptdetailfinishMapper.selectList(query));
        }
        return ordersList;
    }
	

    @DataSourceAnnotation
    @Override
    public void updateByWrapper(String whseid, LambdaUpdateWrapper<ApiReceiptfinish> wrapper) {
        baseMapper.update(null,wrapper);
    }

    @DataSourceAnnotation
    @Override
    public void addApiReceiptfinish(String wmwhseid,ApiReceiptfinish o) {
    	for(ApiReceiptdetailfinish od : o.getDetails()){
    		apiReceiptdetailfinishMapper.insert(od);
    	}
        baseMapper.insert(o);
    }

    @DataSourceAnnotation
	@Override
	public List<ApiReceiptfinish> selectApiReceiptByWrapperNoDetail(String whseid,
			LambdaQueryWrapper<ApiReceiptfinish> queryWrapper) {
		return baseMapper.selectList(queryWrapper);
	}
}
